package com.yanqu.road.server.cmd.mail;

import com.yanqu.road.pb.mail.MailProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.mail.MailModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.server.command.Cmd;

@Cmd(code = Protocol.S_MAIL_READ_MAIL, desc = "阅读邮件")
public class ReadMailCmd extends AbstractCommand {

	String mailUid;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		MailProto.MailReadReqMsg req = MailProto.MailReadReqMsg.parseFrom(packet.getBytes());
		mailUid = req.getMailUid();
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		MailModule mailModule = player.getModule(MailModule.class);
		ret = mailModule.readUserMail(mailUid);
	}

	@Override
	public void sendData(GamePlayer player) {
		MailProto.MailReadRespMsg.Builder builder = MailProto.MailReadRespMsg.newBuilder();
		builder.setRet(ret);
		player.sendPacket(Protocol.U_MAIL_READ_MAIL, builder);
	}

}
